<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html:html>
<head>	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/sampleForm.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/me.css" />	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/help/help.css" />
	<title>บันทึกใบขอเบิกใช้สินค้า, วัตถุดิบ (BCStkIssue2, BCStkIssueSub2)</title>
	<script type='text/javascript' src='/ittl/dwr/interface/BCProjectService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/interface/ItemLocationService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>

	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.bgiframe.min.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.ajaxQueue.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/thickbox-compressed.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.autocomplete.js' ></script>
	
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata2.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata2Name.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata31.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartment.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartmentName.js' ></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/mainOLD.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/thickbox.css" />
 
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery.validate.js" ></script>
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery-1.4.2.min1.js" ></script>


<!-- start add/remove  
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery-latest.pack.js'></script>	
-->	
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery.highlightFade.js'></script>
		
<!-- end add/remove  -->

<style type="text/css">
#form1 label.error {
	font-size: 1.0em;
	color: red;
}
</style>
 	
<script language="JavaScript">
 



$(document).ready(function() {
	 
	//$("#datepicker").datepicker();
	
	
	$("#form1").validate({
		
			
		submitHandler: function() {
			alert("txt1="+document.getElementById("txt1").value);
			alert("submitted!22");
			//$('#dialog-confirm').dialog('open');
			form.submit();
		},
				
		rules: {		
			price1: {
				required: 	true,
				number:		true
			},
			price2: {
				required: 	true,
				number:		true
			},
			price3: {
				required: 	true,
				number:		true
			},
			price4: {
				required: 	true,
				number:		true
			},
			amount1: {
				required: 	true,
				number:		true
			},
			amount2: {
				required: 	true,
				number:		true
			},
			amount3: {
				required: 	true,
				number:		true
			},
			amount4: {
				required: 	true,
				number:		true
			}			
									
		},
		messages: {

			price1: "*",
			price2: "*",				
			price3: "*",
			price4: "*",
			amount1: "*",
			amount2: "*",				
			amount3: "*",
			amount4: "*"			
			
		},

		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			//alert("errorPlacement");			
			if ( element.is(":radio") ) {
				alert("radio");
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ) {
				alert("checkbox");
				error.appendTo ( element.next() );
			}else {
				/*alert(element("#itemCode1"));
				if(element.is("#itemCode1")) {
					error.appendTo( "#qty1-error" );
				}else {
					error.appendTo( element.parent().next() );	
				}*/
				//error.insertAfter('#qty1-error');
				error.appendTo( element.parent().next() );
			}
		}		
	});
			
});

</script>  

<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var inputNo;
var itemName = "";
var code;
var itemName;
var whCode;
var shelfCode;
var shelfName;

function getData(var1,x) {	
	inputNo = x;
	ItemLocationService.getData( var1, loadinfo );	  
}

<!--  ส่วนที่ 3 -->
function loadinfo(data)
{
	code 	  = data.code;
	itemName  = data.name1;
	whCode 	  = data.whCode;
	shelfCode = data.shelfCode;
	shelfName = data.shelfName;
	unitCode = data.unitCode;
	unitName = data.unitName;

	ittl_row = data.ittl_row;
	ittl_shelf = data.ittl_shelf;
	
	switch(inputNo) {
	case 1:	dwr.util.setValue("itemCode1", code);
			dwr.util.setValue("itemName1", itemName);
			dwr.util.setValue("whCode1", whCode);
			dwr.util.setValue("whCode11", whCode);
			dwr.util.setValue("unitCode1", unitCode);
			dwr.util.setValue("unitName1", unitName);
			//redirectN(0, document.getElementById('shCode1'));		
			
			dwr.util.setValue("ittl_row1", ittl_row);
			dwr.util.setValue("ittl_shelf1", ittl_shelf);						
			break;
			
	case 2:	dwr.util.setValue("itemCode2", code);
			dwr.util.setValue("itemName2", itemName);
			dwr.util.setValue("whCode2", whCode);			
			dwr.util.setValue("unitCode2", unitCode);
			dwr.util.setValue("unitName2", unitName);
			//redirectN(0, document.getElementById('shCode2'));
			
			dwr.util.setValue("ittl_row2", ittl_row);
			dwr.util.setValue("ittl_shelf2", ittl_shelf);						
			break;
			
	case 3:	dwr.util.setValue("itemCode3", code);
			dwr.util.setValue("itemName3", itemName);
			dwr.util.setValue("whCode3", whCode);			
			dwr.util.setValue("unitCode3", unitCode);
			dwr.util.setValue("unitName3", unitName);
			//redirectN(0, document.getElementById('shCode3'));
			
			dwr.util.setValue("ittl_row3", ittl_row);
			dwr.util.setValue("ittl_shelf3", ittl_shelf);						
			break;
	case 4:	dwr.util.setValue("itemCode4", code);
			dwr.util.setValue("itemName4", itemName);
			dwr.util.setValue("whCode4", whCode);			
			dwr.util.setValue("unitCode4", unitCode);
			dwr.util.setValue("unitName4", unitName);
			//redirectN(0, document.getElementById('shCode4'));
			dwr.util.setValue("ittl_row4", ittl_row);
			dwr.util.setValue("ittl_shelf4", ittl_shelf);						
			break;
	case 5:	dwr.util.setValue("itemCode5", code);
			dwr.util.setValue("itemName5", itemName);
			dwr.util.setValue("whCode5", whCode);			
			dwr.util.setValue("unitCode5", unitCode);
			dwr.util.setValue("unitName5", unitName);
			//redirectN(0, document.getElementById('shCode5'));//ใช้ document.form1.shelfCode5 จะทำงานได้บน IE แต่ไม่ไได้บน FF
			dwr.util.setValue("ittl_row5", ittl_row);
			dwr.util.setValue("ittl_shelf5", ittl_shelf);						
			break;
	}		
}

function redirectN(x, tempN){
	
	var groupsN=5;//document.form1.shelfCode1.options.length
	var groupN=new Array(groupsN);
	for (i=0; i<groupsN; i++)
		groupN[i]=new Array();

	//var tempN=document.form1.shelfCode1;	
	//alert("tempN.options.length-1 = "+(tempN.options.length-1));
	for (m=tempN.options.length-1;m>=0;m--) {
		//alert(tempN.options[m]);
		tempN.options[m]=null;
	}
	
	if(shelfName != null) {
		for (i=0; i<shelfName.length; i++) {
			groupN[0][i]=new Option(shelfName[i], shelfCode[i]);
		}
					
		for (i=0;i<groupN[x].length;i++){
			text = groupN[x][i].value+":"+groupN[x][i].text;
			tempN.options[i]=new Option(text,groupN[x][i].value);
		}
		tempN.options[0].selected=true;
	}
}
</script>
<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getProject() {
	//alert("bcproject"+form1.projectCode.value); ใช้ใน ff ไม่ผ่าน			
	BCProjectService.getProject( document.getElementById("suggestProject").value, loadinfoProject );			  
}

<!--  ส่วนที่ 3 -->
function loadinfoProject(project){		
	//dwr.util.setValue("projectCode", project.name);
	dwr.util.setValue("projectName", project.name);			     
}
</script>	

<script type="text/javascript">
function alertValue() {
	alert(document.getElementById('htmlElementTest').value)
}
</script>

	<link type="text/css" href="<%= request.getContextPath() %>/css/datepicker/css/ui.all.css" rel="stylesheet" /> 
	
	<script type="text/javascript" src="<%= request.getContextPath() %>/css/datepicker/lib/jquery-ui-1.5.3.min.js"></script>
	

	<script type="text/javascript">
		$(document).ready(function(){
    			$("#docDate").datepicker({ altField: 'input#docDate', altFormat: 'yy-mm-dd' });
  		});

  		function calAmount(id) {
  	  		var qty = document.getElementById('qty'+id).value;
  	  		var price = document.getElementById('price'+id).value
			document.getElementById('amount'+id).value = qty*price;  			
  		}
  		function calPrice(id) {
  	  		var qty = document.getElementById('qty'+id).value;
  	  		var amount = document.getElementById('amount'+id).value
			document.getElementById('price'+id).value = amount/qty;  	
					
  		}  		
	</script>


</head>

<body><br />
<div id="wrapper">
	<!-- 
		<div id="header"><img src="images/kiuchilogo.png" width="305" height="80" /></div>
	 -->	 
	<div id="menu"><ul id="nav"></ul></div>

	<div id="content">
		<div id="menuNav"><a href='<%=request.getContextPath() %>/Login.do?mode=check'>หน้าหลัก</a> 
		>> คลังพัสดุ - Store กลาง  >> บันทึก พ.1 (ขอซื้อ) >> รายการ พ.1 (ขอซื้อ)  </div><br />
			
	<div style="background: #ffffff;">
	<p align="center" id="titleIssueType">ประเภทการเบิก : ${issueTypeName}</p>
	<!-- <p align="center">แผนก  : ${departCode }</p>  --><br></br>	
	
	<center><div style="border: 1px solid;   width:200px; background: #ffc080" >ใส่ราคาเท่านั้น</div></center>
	
	<html:form action="/StkReq.do?mode=updatePrice" styleId="form1"  >	        
        <!-- 
        <input type="hidden" name="departCode" value="${issue2form.departCode }" />
         -->
        <input type="hidden" name="issueType" value="${issue2form.issueType}" />
        
	<div id="userPw01">
	<fieldset>
		<legend><b>ข้อมูลใบขอเบิกใช้สินค้า, วัตถุดิบ</b></legend>
		   <center> 
		   <table border="0" >
			<tr>
				<td width="120">เลขที่เอกสาร </label></td>
				<td width="140"><input type="text" name="docNo" value="${issue2form.docNo}" readonly="readonly" id="docNo" ></td>
				<td ></td>				
			</tr>
			<tr>
				<td > วันที่ขอเบิก</label></td>
				<td ><input type="text" name="docDate" maxlength="100" value="${issue2form.docDate}" readonly="readonly"></td>
				<td ></td>					
			</tr>			
			<tr>
				<td >ฝ่ายผู้เบิก </label></td>
				<td ><input type="text" name="iTTL_deptPay" value="${issue2form.iTTL_deptPay }" id="suggestDeptPay" readonly="readonly"></td>
				<td ></td>	
				
			</tr>			 		
			<tr>
				<td>ฝ่ายชำระเงิน</label></td>
				<td><input type="text" name="departCode" maxlength="3" value="${issue2form.departCode }" id="departCode" readonly="readonly"></td>
				<td ></td>			
			</tr>
 			<tr>
 				<td>หน่วยงบ</label></td>
 				<td><input type="text" name="projectCode" value="${issue2form.projectCode }" id="suggestProject" readonly="readonly" onblur="getProject()"  ></td>
 				<td ></td>				 				 				
 			</tr>			
 			<tr>
 				<td>ผู้บันทึกข้อมูล</label></td>
 				<td><input type="text" name="personCode" value="${issue2form.personCode}" readonly="readonly" ></td>
 				<td ></td>	
 			</tr>
 			<tr>
 				<td>หมายเหตุ</label></td>
 				<td colspan="2"><input type="text" name="myDescription" value='${issue2form.myDescription }' maxlength="200" size="50" readonly="readonly"></td>
 				
 			</tr>
 			 			 			 				 							
		</table>
		</center>
     </fieldset></div>
    <div id="items"> 
     <fieldset>
     	<legend><b>รายการสินค้า, วัตถุดิบ</b></legend>     	     	
     		<input type="hidden" id="id" value="0">
     	<center>	     		          	
		<table border="0" >
			<thead>
				<tr id="rHead">
					<th width="24"></th>
				  <th width="100" align="center">รหัสสินค้า</th>
				  <th width="10"></th>
				  <th width="270" align="center">ชื่อรายการ</th>
				  <th width="10"></th>				
				  <th>แถว</th>
				  <th>ชั้น</th>
				  <th width="70"  align="center">หน่วยนับ</th>
				  <th width="10"></th>
				  <th width="60"  align="center">จำนวน</th> 
				  <th width="60"></th>
				  <th width="60"  align="center">ราคาต่อหน่วย</th> 
				  <th width="60"></th>				
				  <th width="60"  align="center">จำนวนเงิน</th> 
				  <th width="60"></th>				    
				  <th width="60"  align="center">หน่วยที่เบิก</th>
				  <th width="60"></th>				
				</tr>						
			</thead>
			
			<tbody id="inputs">
				<tr id="r1">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode1" value="${issue2form.itemCode1 }" size="12" 
				  				readonly="readonly">			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName1" value='${issue2form.itemName1 }' maxlength="200" size="40" id="itemName1" readonly="readonly">					
						<input	type="hidden" name="whCode1" value="${issue2form.whCode1}" id="whCode1">
					</td><td></td>					
					
					<td><label id="ittl_row1"></label></td>
					<td><label id="ittl_shelf1"></label></td>
					
					<td align="center"><input	type="text"	name="unitName1" value="${issue2form.ittl_unitName1}" size="5" id="unitName1" readonly="readonly">					
						<input	type="hidden" name="unitCode1" value="${issue2form.unitCode1}" id="unitCode1">
					</td><td></td>
					<td><input	type="text"	name="qty1" value="${issue2form.qty1}" maxlength="15" size="5" id="qty1" readonly="readonly"></td>
					<td></td>
					<td><input	type="text"	name="price1" value="${issue2form.price1}" size="5" id="price1" onchange="calAmount(1)"></td>
					<td>&nbsp;</td>
					<td><input	type="text"	name="amount1" value="${issue2form.amount1}" size="5" id="amount1" onchange="calPrice(1)" ></td>
					<td>&nbsp;</td>
					<td><input	type="text"	name="division1" value='${issue2form.division1}' id="division1" readonly="readonly"></td>
					<td></td>					
				</tr>

<c:if test="${!empty issue2form.itemCode2}">  			
				<tr id="r2">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode2" value="${issue2form.itemCode2 }" size="12" 
				  				 
				  				readonly="readonly" 
				  				>			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName2" value='${issue2form.itemName2 }' maxlength="200" size="40" id="itemName2" readonly="readonly" >					
						<input	type="hidden" name="whCode2" value="${issue2form.whCode2}" id="whCode2">
					</td><td></td>					

					<td><label id="ittl_row2"></label></td>
					<td><label id="ittl_shelf2"></label></td>
					
					<td align="center"><input	type="text"	name="unitName2" value="${issue2form.ittl_unitName2}" size="5" id="unitName2" readonly="readonly" >					
						<input	type="hidden" name="unitCode2" value="${issue2form.unitCode2}" id="unitCode2">
					</td><td></td>
					<td><input	type="text"	name="qty2" value="${issue2form.qty2}" maxlength="15" size="5" id="qty2" readonly="readonly" ></td>
					<td></td>
					<td><input	type="text"	name="price2" value="${issue2form.price2}" size="5" id="price2" onchange="calAmount(2)"></td>
					<td>&nbsp;</td>
					<td><input	type="text"	name="amount2" value="${issue2form.amount2}" size="5" id="amount2" onchange="calPrice(2)"></td>
					<td>&nbsp;</td>					
					<td><input	type="text"	name="division2" value='${issue2form.division2}' id="division2" readonly="readonly" ></td>
					<td></td>					
				</tr>
</c:if>
<c:if test="${!empty issue2form.itemCode3}">  
				<tr id="r3">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode3" value="${issue2form.itemCode3 }" size="12" 
				  				 
				  				readonly="readonly" >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName3" value='${issue2form.itemName3 }' maxlength="200" size="40" id="itemName3" readonly="readonly" >					
						<input	type="hidden" name="whCode3" value="${issue2form.whCode3}" id="whCode3">
					</td><td></td>
					
					<td><label id="ittl_row3"></label></td>
					<td><label id="ittl_shelf3"></label></td>					
										
					<td align="center"><input	type="text"	name="unitName3" value="${issue2form.ittl_unitName3}" size="5" id="unitName3" readonly="readonly" >					
						<input	type="hidden" name="unitCode3" value="${issue2form.unitCode3}" id="unitCode3">
					</td><td></td>
					<td><input	type="text"	name="qty3" value="${issue2form.qty3}" maxlength="15" size="5" id="qty3" readonly="readonly" ></td>
					<td></td>
					<td><input	type="text"	name="price3" value="${issue2form.price3}" size="5" id="price3" onchange="calAmount(3)"></td>
					<td>&nbsp;</td>
					<td><input	type="text"	name="amount3" value="${issue2form.amount3}" size="5" id="amount3" onchange="calPrice(3)"></td>
					<td>&nbsp;</td>					
					<td><input	type="text"	name="division3" value='${issue2form.division3}' id="division3" readonly="readonly" ></td>
					<td></td>					
				</tr>
</c:if>
<c:if test="${!empty issue2form.itemCode4}">  
				<tr id="r4">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode4" value="${issue2form.itemCode4 }" size="12" 
				  				 
				  				readonly="readonly" >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName4" value='${issue2form.itemName4 }' maxlength="200" size="40" id="itemName4" readonly="readonly" >					
						<input	type="hidden" name="whCode4" value="${issue2form.whCode4}" id="whCode4">
					</td><td></td>		
					
					<td><label id="ittl_row4"></label></td>
					<td><label id="ittl_shelf4"></label></td>					
								
					<td align="center"><input	type="text"	name="unitName4" value="${issue2form.ittl_unitName4}" size="5" id="unitName4" readonly="readonly" >					
						<input	type="hidden" name="unitCode4" value="${issue2form.unitCode4}" id="unitCode4">
					</td><td></td>
					<td><input	type="text"	name="qty4" value="${issue2form.qty4}" maxlength="15" size="5" id="qty4" readonly="readonly" ></td>
					<td></td>
					<td><input	type="text"	name="price4" value="${issue2form.price4}" size="5" id="price4" onchange="calAmount(4)"></td>
					<td>&nbsp;</td>
					<td><input	type="text"	name="amount4" value="${issue2form.amount4}" size="5" id="amount4" onchange="calPrice(4)"></td>
					<td>&nbsp;</td>					
					<td><input	type="text"	name="division4" value='${issue2form.division4}' id="division4" readonly="readonly" ></td>
					<td></td>					
				</tr>
</c:if>												
			</tbody>
			<tfoot>

			</tfoot>						
		</table>
		</center><br></br>     	
		<font size='2'>หมายเหตุ : <font color="red">*</font> คือข้อมูลที่ต้องใส่</font>
     </fieldset>
 	</div>
 	
 	<table border="0" align="center" width="100%">
 		<tr>
 			<td align="center" ><html:submit  value="บันทึกการแก้ไขใบขอเบิก พ.1" onclick="return confirm('ยืนยัน ?');" /></td>
 			<td align="center" ></td> 			
 			<td align="center" ><html:button  value="กลับไปหาดูรายการบันทึก พ.1" property="show1" 
 			onclick="gotoStkIssue2Show()"  /></td>
 		</tr>
 	</table>    	    	    	
    </html:form><br>
    </div>
    </div>
    </div>
   

<input type="hidden" value="${issue2form.itemCode2}" id="item2">
<input type="hidden" value="${issue2form.itemCode3}" id="item3">
<input type="hidden" value="${issue2form.itemCode4}" id="item4">

<script type="text/javascript">

var item2 = document.getElementById("item2").value;
var item3 = document.getElementById("item3").value;
var item4 = document.getElementById("item4").value;

	if(item2=="") {
		idArray[1] = 0;
	}
	if(item3=="") {
		idArray[2] = 0;
	}
	if(item4=="") {
		idArray[3] = 0;
	}	

function refreshForm() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	var docNo = document.getElementById("docNo").value
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/StkReq.do?mode=edit&docNo="+docNo;	
}
function gotoStkIssue2Show() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/StkReq.do?mode=show";
}
</script>
<input type="hidden" value="<%=request.getLocalAddr() %>" id="localAddr">
<input type="hidden" value="<%=request.getLocalPort() %>" id="localPort">
<input type="hidden" value="<%=request.getContextPath() %>" id="contextPath">






<!-- 
<a href="#" class="add"><img src="add.png" width="24" height="24" alt="add" title="add input" /></a> 
<a href="#" class="reset"><img src="reset.png" width="24" height="24" alt="reset" /></a>
 -->
 
</body>
</html:html>